package com.woniuxy.service.impl;

import com.woniuxy.dao.PropertyMapper;
import com.woniuxy.dao.ServerOrdersMapper;
import com.woniuxy.pojo.ServerOrders;
import com.woniuxy.service.ServerOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class ServerOrderServiceImpl implements ServerOrderService {


    @Autowired
    private ServerOrdersMapper serverOrdersMapper;

    @Autowired
    private PropertyMapper propertyMapper;

    //根据物业点击确认完成服务后检查或做相应的处理
    @Override
    public ServerOrders checkOrderAccomplish(Long soid) {
        return serverOrdersMapper.checkOrderAccomplish(soid);
    }


    //服务完成后将服务完成时间写入数据库
    @Override
    public void setEndTimeById(Long soid, Date date) {
        serverOrdersMapper.setEndTimeById(soid,date);
    }


    //用户超时未确认完成操作
    @Override
    public void updateServerOrderByOvertime(Long id,Double price) {
        //修改订单状态
        serverOrdersMapper.updateServerOrderByOvertime(id);
        //将服务费用打入商家账户
        //先根据订单号查询出是哪家物业公司
        Long pid = serverOrdersMapper.findPropertyIdByOrderId(id);
        System.out.println("服务的商家为"+pid+"公司");
        //修改金额
        propertyMapper.updateBalanceByPid(pid,price);
    }
}
